package com.googlecode.horncomb.bean.id.generator;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * JDK的UUID生成器
 * @author Daniel
 */
public class JdkUUIDGenerator implements IdGenerator<String> {
	@SuppressWarnings("unchecked")
	public boolean support(Class type) {
		return true;
	}

	/**
	 * 自动生成指定个数的UUID
	 * @param args
	 *            生成的数量
	 */
	public static void main(String... args) {
		int times = 1;
		if (args != null && args.length > 0) {
			times = Integer.valueOf(args[0]);
		}
		String[] ids = new JdkUUIDGenerator().generateIds(times);
		for (String id : ids) {
			System.out.println(id);
		}
	}

	public String[] generateIds(int times) {
		List<String> idLst = new ArrayList<String>(times);
		for (int i = 0; i < times; i++) {
			idLst.add(this.generateId());
		}
		return idLst.toArray(new String[] {});
	}

	/**
	 * @see com.googlecode.horncomb.bean.id.generator.IdGenerator#generateId()
	 */
	private String generateId() {
		return UUID.randomUUID().toString();
	}

	/**
	 * this method ignore any parameter. please use {@link #generateId()}
	 * <p>
	 * {@inheritDoc}
	 */
	public String generateId(Object object) {
		return this.generateId();
	}
}
